showDialogueBox = function (options) {

    var currentDialogue = '#' + options.id;

    if ($('.dialogueOverlay').length) {
        var currentZindex = $('.dialogueOverlay').css("z-index") + 1;
        if ($(currentDialogue).length) {
            return false;
        }
    }

    var loaderHTML = '<img src="../resources/img/loading.jpg" />';
    var closeBtn = '<div class="xbtn">×</div>';
    var buttonHTML = '';

    if (options.buttons && options.type == 'confirm') {
        $.each(options.buttons, function (label, params) {
            buttonHTML += '<input type="button" class="btn ' + params['class'] + '" value="' + label + '" />';
            if (!params.action) {
                params.action = function () {
                };
            }
        });
    }

    var markup = [
        '<div id="', options.id, '" class="dialogueOverlay ', options.type, '">',
        '<div class="dialogueBox">', loaderHTML, closeBtn,
        '<div class="title">', options.title, '</div>',
        '<div class="message">', options.message, '</div>',
        '<div class="btns">', buttonHTML, '</div></div></div>'
    ].join('');

    $(markup).hide().appendTo('body').fadeIn(200, function () {
        $(this).find('.dialogueBox').slideToggle(400)
    });
    $(currentDialogue).css({"z-index": currentZindex});
    $(currentDialogue).find('.dialogueBox').css({"margin-left": -($(currentDialogue).find('.dialogueBox').outerWidth() / 2) + "px"});

    if (options.type == 'success') {
        //TODO ADD
        $('.dialogueBox .message').css("display", "block");
        $('.dialogueBox .btns').css("display", "none");
        $(currentDialogue).timer = null;
        $(currentDialogue).timer = setTimeout(function () {
            hideDialogueBox(options.id);
        }, 2600);
    }

    if (options.type == 'loading') {
        $('.dialogueBox img').css("display", "block");
        $('.dialogueBox').css("left", "50%");
        $('.dialogueBox').css("margin-left", "-50px");
        $('.dialogueBox').css("opacity", "0.9");
        $('.dialogueBox').css("padding", "0");
        $('.dialogueBox').css("width", "83px");
        $('.dialogueBox').css("height", "83px");
        $('.dialogueBox').css("overflow-y", "hidden");
        $('.dialogueBox').css("overflow-x", "hidden");
        $('.dialogueBox').css("height", "100px");
        $('.dialogueBox .xbtn').css("display", "none");
    }

    $('.dialogueBox .xbtn').click(function () {
        hideDialogueBox(options.id);
    });

    if (options.buttons && options.type == 'confirm') {

        $('.dialogueBox .btn.btn-primary').focus();

        //TODO ADD
        $('.dialogueBox .message').css("display", "block");

        var buttons = $('.dialogueBox .btn'),
            i = 0;

        $.each(options.buttons, function (label, params) {
            buttons.eq(i++).click(function () {

                // use action from options
                params.action();

                // hide DialogueBox
                hideDialogueBox(options.id);
                return false;
            });
        });
    }
}

hideDialogueBox = function (dialogueID) {
    $('#' + dialogueID + ' .dialogueBox').slideToggle(400, function () {
        $('#' + dialogueID).fadeOut(200, function () {
            $('#' + dialogueID).remove();
            $('#' + dialogueID).timer = null;
        })
    });
}
